package itheima.zuoye.Test2;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {
    public static void main(String[] args) {
        // Map嵌套List集合保存年级学生的信息，Map的键字符串类型表示年级，值List集合保存一个班级的学生信息

        Map<String, List<Student>> gradeStudentMap = new HashMap<>();
        gradeStudentMap.put("1年级", List.of(
                new Student("1-1", "张三", 20),
                new Student("1-2", "李四", 28),
                new Student("1-3", "王六", 30)));
        gradeStudentMap.put("2年级", List.of(
                new Student("2-1", "王五", 29),
                new Student("2-2", "赵六", 19),
                new Student("2-3", "孙八", 20)));
        gradeStudentMap.put("3年级", List.of(
                new Student("3-1", "孙七", 18),
                new Student("3-2", "周八", 23),
                new Student("3-3", "吴九", 22)));
        gradeStudentMap.put("4年级", List.of(
                new Student("4-1", "郑十", 21),
                new Student("4-2", "王十一", 19),
                new Student("4-3", "王十二", 20)));
        //遍历出年纪信息，要求每个班级的学生按照年龄升序打印输出
        gradeStudentMap.forEach((grade, students) -> {
            students.stream()
                    .sorted(Comparator.comparing(Student::getAge))
                    .forEach(student -> System.out.println("年级: " + grade + ", 姓名: " + student.getName() + ", 年龄: " + student.getAge()));
        });


    }

}
